<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm"  ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="商城名称" prop="mallName" :rules="[{ required: true, message: '请输入商城名称'}]">
        <el-input v-model="dataForm.mallName" placeholder="商城名称"></el-input>
      </el-form-item>
      <el-form-item label="服务器域名" prop="host" :rules="[{ required: true, message: '请输入服务器域名'}]">
        <el-input v-model="dataForm.host" placeholder="服务器域名"></el-input>
      </el-form-item>
	  
	  
	  
	  <el-form-item label="公众号" prop="mpid" :rules="[{ required: true, message: '请选择公众号'}]">
        <el-col :span="8">
          <el-select v-model="dataForm.mpid"
                    
                    style="width: 250px"
                    placeholder="请选择">
			
            <el-option  v-for="item in mps"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id">
            </el-option>
			
          </el-select>
        </el-col>
      </el-form-item>
	  <el-form-item label="商城类型" prop="mallType" :rules="[{ required: true, message: '请选择商城类型'}]">
        <el-col :span="8">
          <el-select v-model="dataForm.mallType"
                    
                    style="width: 250px"
                    placeholder="请选择">
			
            <el-option  
                      key="0"
                      label="普通商城"
                      value="0">
            </el-option>
			<el-option  
                      key="1"
                      label="VIP积分商城"
                      value="1">
            </el-option>
			
          </el-select>
        </el-col>
      </el-form-item>
	  
      
	  
      <el-form-item label="客服链接" prop="customerServ" :rules="[{ required: false, message: '请输入企业微信客服推广链接'}]">
        <el-input v-model="dataForm.customerServ" placeholder="请输入企业微信客服推广链接"></el-input>
      </el-form-item>
      
	  
	  
      
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { isEmail, isMobile } from '@/utils/validate'
  import { Debounce } from '@/utils/debounce'
  import { encrypt } from '@/utils/crypto'
  export default {
    data () {
      
      return {
        visible: false,
        roleList: [],
		malls: [],
		mps: [],
        dataForm: {
          id: 0,
          appid: '',
          mallName: '',
          host: '',
          menuName: '',
          mpid: '',
		  mallType: '',
		  customerServ: '',
		  mpName: '',
          roleIdList: [],
          status: 1,
		  mallid: 0
        }
        
      }
    },
	
    methods: {
	  
		
      init (id) {
		this.$http({
			url: this.$http.adornUrl('/sys/mp/listMpList'),
			method: 'get'
			
		  }).then(({ data }) => {
			let _firstData=data
			
			this.mps = _firstData
			

				this.dataForm.id = id || 0
				if (this.dataForm.id) {
					this.$http({
					  url: this.$http.adornUrl(`/prod/mall/info/${this.dataForm.id}`),
					  method: 'get',
					  params: this.$http.adornParams()
					}).then(({data}) => {
					  this.dataForm.mallName = data.mallName
					  this.dataForm.host = data.host
					  this.dataForm.menuName = data.menuName
					  this.dataForm.mpid = data.mpid
					  this.dataForm.mallType = data.mallType
					  this.dataForm.customerServ=data.customerServ
					  
					})
				}
				this.visible = true
				  this.$nextTick(() => {
					this.$refs.dataForm.resetFields()
				  })
			
			
		  })
		  
        
        
      },
      // 表单提交
      dataFormSubmit: Debounce(function () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
		    console.log(this.dataForm.password,encrypt(this.dataForm.password))
            this.$http({
              url: this.$http.adornUrl(`/prod/mall`),
              method: this.dataForm.id ? 'put' : 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'mallName': this.dataForm.mallName,
                'host': this.dataForm.host,
                'menuName': this.dataForm.menuName,
                'mpid': this.dataForm.mpid,
                'mallType': this.dataForm.mallType,
                'customerServ': this.dataForm.customerServ
              })
            }).then(({data}) => {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            })
          }
        })
      })
    }
  }
</script>
